
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<% include import.ejs %>
<link rel="stylesheet" href="/stylesheets/game.css">
<title>厦门全民狂欢节</title>

<body>
    <div class="Brand_logo">
        <img src="/images/game_logo.png">
    </div>
    <div class="bowl">
        <img id="animationImg" src="/images/0.png">
    </div>
    <div class="start">
        <img src="/images/game_Start.png">
    </div>

    <div class="frequency">您还有<span id="frequency"><%=frequency%></span>次机会</div>

    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        $(function() {
            $.get('http://www.houke.net.cn/wechatShare/sharePage', {
                'req_url': location.href.split('#')[0]
            }, function(data) {
                shareClick(data.appId, data.timestamp, data.noncestr, data.signature, '厦门全民狂欢节', 'http://www.houke.net.cn:9098/www/weChat_login.html', 'http://www.houke.net.cn:9098/www/images/psd11061_03.png');
            }, "jsonp");

            function shareClick(appId, timestamp, noncestr, signature, title, link, imgUrl) {
                var appId = appId;
                var timestamp = timestamp;
                var noncestr = noncestr;
                var signature = signature;
                // alert(appId+'---'+timestamp+'----'+noncestr+'-----'+signature);
                wx.config({
                    debug: false,
                    appId: appId,
                    timestamp: timestamp,
                    nonceStr: noncestr,
                    signature: signature,
                    jsApiList: [
                        'onMenuShareTimeline',
                        'onMenuShareAppMessage'
                    ]
                });
                wx.ready(function() {
                    wx.onMenuShareTimeline({
                        title: title,
                        link: link,
                        imgUrl: imgUrl,
                        success: function() {
                            $.get('/moonCakeBetting/game/frequency',{gradient:2},function(data){
                                if(data.code == 100){
                                    alert('恭喜你，分享成功！获得5次博饼次数！');
                                    $('#frequency').text(data.frequency)
                                }else if(data.code == 101){
                                    alert(data.error)
                                }
                            },'json')
                        },
                        cancel: function() {}
                    });
                    wx.onMenuShareAppMessage({
                        title: title, // 分享标题
                        desc: title, // 分享描述
                        link: link, // 分享链接
                        imgUrl: imgUrl, // 分享图标
                        type: '', // 分享类型,music、video或link，不填默认为link
                        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                        success: function() {

                            alert('恭喜你，分享成功！');
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function() {
                            // 用户取消分享后执行的回调函数
                        }
                    });
                });
                wx.error(function(res) {
                    //						alert('wx.error: '+JSON.stringify(res));
                });
            }
            var timer = '';
            var temp = 0;
            $('.start').click(function() {
                var Prize;
                if($('#frequency').text() == 0){
                    alert('没有次数了,可以分享给朋友圈获得五次次数!')
                }else {
                    $.get('/moonCakeBetting/game/frequency',{gradient:1},function(data){
                        console.log(data.frequency)
                        $('#frequency').text(data.frequency)
                        Prize = data.Prize
                    },'json')
                    clearInterval(timer);
                    timer = setInterval(function() {
                        var a = '';
                        a = Math.ceil(Math.random() * 6);
                        $('#animationImg').attr('src',"../images/" + a + ".png");
                        temp++;
                        if(temp>60){
                            clearInterval(timer);
                            temp = 0;
                            alert(Prize)
                        }
                    },60);
                }
            })
        })
    </script>
</body>